//
//  TestViewController.m
//  自己练习
//
//  Created by Mac on 15-11-24.
//  Copyright (c) 2015年 yqf. All rights reserved.
//

#import "TestViewController.h"
#import "ViewController.h"
@interface TestViewController ()
{
    NSArray * data;
    NSArray * detail;
    NSArray * headers;
}
@end

@implementation TestViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    data =@[
            @[@"安娜",@"安全"],
            @[@"速度",@"白豆腐"]
            ];
    detail=@[
             @"1",
             @"2",
             @"3"
             ];
    headers=@[
              @"a",
              @"b",
              @"c"
              ];
    self.navigationItem.rightBarButtonItem=self.editButtonItem;
    // Do any additional setup after loading the view from its nib.
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return data.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [data[section] count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
    cell.textLabel.text=data[indexPath.section][indexPath.row];
    cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
    return  cell;
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return headers[section];
}

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    ViewController * con =[ViewController new];
    [self.navigationController pushViewController:con animated:YES];    
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
    
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        NSMutableArray *arr = data.mutableCopy;
        NSMutableArray *inArr = [data[indexPath.section] mutableCopy];
        [inArr removeObjectAtIndex:indexPath.row];
        
        [arr replaceObjectAtIndex:indexPath.section withObject:inArr];
        data = arr;
        
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
